package cvut.fit.dpo.arithmetic;

import java.util.Iterator;
import java.util.LinkedList;

import cvut.fit.dpo.arithmetic.elements.ExpressionElement;
import cvut.fit.dpo.arithmetic.elements.Number;
import cvut.fit.dpo.arithmetic.iterator.AbstractIterator;

/**
 * Represents number in the arithmetic expression
 * 
 * @author Jan Kurš
 */
public class NumericOperand extends ArithmeticExpression {
	final private Integer value;

	public NumericOperand(final Integer value) {
		this.value = value;
	}

	@Override
	public Integer evaluate() {
		return value;
	}

	@Override
	public ExpressionElement getRepresentationInExpresionModel() {
		return new Number(value);
	}

	@Override
	public Iterator<ExpressionElement> getInOrderIterator() {
		return createNumericIterator();
	}

	@Override
	public Iterator<ExpressionElement> getPostOrderIterator() {
		return createNumericIterator();
	}

	private Iterator<ExpressionElement> createNumericIterator() {
		return new AbstractIterator() {

			@Override
			protected Iterator<ExpressionElement> createIterator() {
				LinkedList<ExpressionElement> list = new LinkedList<ExpressionElement>();
				list.add(getRepresentationInExpresionModel());
				return list.iterator();
			}

		};
	}
}
